package cn.ddiancan.xddcloud.sentinel.cleaner;

import java.util.Collections;

import com.alibaba.csp.sentinel.adapter.web.common.UrlCleaner;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;

public class XddcloudUrlCleaner implements UrlCleaner {

    @Override
    public String clean(String s) {
        FlowRule flowRule = new FlowRule();
        flowRule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER);
        flowRule.setMaxQueueingTimeMs(1000);
        flowRule.setGrade(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER);
        flowRule.setCount(1);
        flowRule.setResource(s);
        FlowRuleManager.loadRules(Collections.singletonList(flowRule));
        return s;
    }
}
